package com.elinkway.infinitemovies.push;

import android.os.Bundle;
import android.text.TextUtils;

import com.elinkway.infinitemovies.bean.PushData;
import com.elinkway.infinitemovies.utils.UmengEventPoster;

public class PushStatsPoster {
	public static void postPushStats(String type){
		 if(TextUtils.equals(type, PushData.TYPE.ALBUM)){
			 UmengEventPoster.postPush(UmengEventPoster.PUSH_TYPE_ALBUM);
		 }
		 else if(TextUtils.equals(type, PushData.TYPE.TOPIC)){
			 UmengEventPoster.postPush(UmengEventPoster.PUSH_TYPE_THEME);
		 }
		 else if(TextUtils.equals(type, PushData.TYPE.HTML)){
			 UmengEventPoster.postPush(UmengEventPoster.PUSH_TYPE_LINK);
		 }
		 else{
			 UmengEventPoster.postPush(UmengEventPoster.PUSH_TYPE_OTHER);
		 }
	}
	/**
	 * 在目标Activity携带的bundle里判断是否有from_push_notification字段，如果有则认定来自于Notification点击
	 * @param bundle
	 * @param type 类型 {@link UmengEventPoster} 中的推送枚举值
	 */
	public static void postPushClickStats(Bundle bundle,String type){
		final String FROM_PUSH_KEY = "from_push_notification";
		if(null!=bundle && bundle.containsKey(FROM_PUSH_KEY)&&bundle.getBoolean(FROM_PUSH_KEY)){
			UmengEventPoster.postPushClick(type);
			// 将值置为false，防止Activity recreate时重新发送
			bundle.putBoolean(FROM_PUSH_KEY, false);
		}
	}
}
